<?php
class AutoTimestampBehavior extends CActiveRecordBehavior {
 
    /**
    * The field that stores the creation time
    */
    public $created = 'created';
    /**
    * The field that stores the modification time
    */
    public $modified = 'modified';
 
 
    public function beforeValidate($on) {
        if ($this->Owner->isNewRecord)
            $this->Owner->{$this->created} = time();
        else
            $this->Owner->{$this->modified} = time();
 
        return true;    
    }
}
?>